import java.util.Scanner;

public class code9_20 {
    public static void main(String[] args) {
        int[] arr1 = {4, 5, 6, 0, 0, 0};
        int[] arr2 = {1, 2, 8};
        int arr2Tail = arr2.length - 1;
        int k = arr1.length - 1;
        int arr1Tail = arr2.length - 1;
        int i = 0;
        while (arr2Tail >= 0 && arr1Tail >= 0) {
            if (arr1[arr1Tail] > arr2[arr2Tail]) {
                arr1[k] = arr1[arr1Tail];
                k--;
                arr1Tail--;
            } else if (arr1[arr1Tail] < arr2[arr2Tail]) {
                arr1[k] = arr2[arr2Tail];
                k--;
                arr2Tail--;
            }
        }
        if (arr2Tail != 0) {
            int ch = arr2Tail;
            for (int j = 0; j <= ch; j++) {
                arr1[k] = arr2[arr2Tail];
                k--;
                arr2Tail--;
            }
        } else {
            for (int j = 0; j < arr1Tail; j++) {
                arr1[k] = arr1[arr1Tail];
                k--;
                arr1Tail--;
            }
        }
        for (int j = 0; j < arr1.length; j++) {
            System.out.print(arr1[j] + " ");
        }

    }
}
    /*public static void main2(String[] args) {
        int[] arr1 = {4,5,6,0,0,0};
        int[] arr2 = {1,2,3};
        //int sz = arr1.length + arr2.length;
        for (int i = 0; i < 3; i++) {
            arr1[arr1.length-3 + i] = arr2[i];
        }
        for (int i = 0; i < 6-1; i++) {
            for (int j = 0; j < 6-i-1; j++) {
                if (arr1[j]>arr1[j+1])
                {
                    int temp = arr1[j];
                    arr1[j] = arr1[j+1];
                    arr1[j+1] = temp;
                }
            }
        }
        for (int i = 0; i < 6; i++) {
            System.out.print(arr1[i]+" ");
        }
    }


    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()){
            String str = scanner.nextLine();
            char[] arrUpper = new char[100];
            char[] arrLower = new char[100];
            for (int i = 0; i < str.length(); i++) {
                char ch = str.charAt(i);
                if(ch >= 'a'&& ch <= 'z'){
                    arrLower[ch-'a'] = ch;
                } else if (ch >= 'A' && ch <= 'Z') {
                    arrUpper[ch-'A'] = ch;
                }
            }
            for (int i = 0; i < arrLower.length; i++) {
                if(arrLower[i] != 0){
                    System.out.print(arrLower[i]+" ");
                }
            }
            for (int i = 0; i < arrUpper.length; i++) {
                if (arrUpper[i] != 0){
                    System.out.print(arrUpper[i]+" ");
                }
            }
        }
    }*/
//}
